package com.esbi.projectwebsocket.collect.toJson;

import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;

public class GsonExample {
    public static void main(String[] args) {
        Person person = new Person("John", 30);
        System.out.println(person);
        Gson gson = new Gson();
        String jsonString = gson.toJson(person);
        System.out.println(jsonString);
        /**
         * 下面写将json字符串转换为java对象
         */
        Gson gson1 = new Gson();
        Person person1 = gson1.fromJson(jsonString, Person.class);
        System.out.print("\33[44;1m"+person1+"\n\33[0m");//紫色背景
    }
}
